import requests
import parsel
from lxml import etree

for page in range(0, 10):
    page = page*10
    # https://www.maoyan.com/board/4?timeStamp=1661957575118&channelId=40011&index=6&signKey=13bb124d65608b1b4a6a2cab0ef2bbd7&sVersion=1&webdriver=false
    url = f'https://www.maoyan.com/board/4?requestCode=d34c88ad33becd185430043986e5625ceurfu&offset={page}'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
    }
    resp = requests.get(url=url, headers=headers)

    et = etree.HTML(resp.text)
    lis_dd = et.xpath('//*[@id="app"]/div/div/div[1]/dl/dd')
    for i in lis_dd:
        name = i.xpath('./div/div/div[1]/p[1]/a/text()')[0]
        star = i.xpath('./div/div/div[1]/p[2]/text()')[0].strip().split('：')[-1]
        release_time = i.xpath('./div/div/div[1]/p[3]/text()')[0].split('：')[-1]
        integer = i.xpath('./div/div/div[2]/p/i[1]/text()')[0]
        fraction = i.xpath('./div/div/div[2]/p/i[2]/text()')[0]
        score = integer + fraction
        print(name, star, release_time, score)


# selector = parsel.Selector(resp.text)
# lis_dd = selector.css('.board-wrapper dd')
# for item in lis_dd:
#     name = item.css('.movie-item-info .name a::text').get()
#     # star = item.xpath('.board-wrapper .movie-item-info .star::text').get()
#     star = item.xpath('//*[@id="app"]/div/div/div[1]/dl/dd/div/div/div[1]/p[2]/text()').get()
#     release_time = item.css('.board-wrapper .movie-item-info .releasetime::text').get()
#     print(name, star, release_time)